<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数实现递归算法</title>
</head>
<body>
    <script>
        // 递归算法考虑两点：
                // 1.先考虑两层
                // 2.考虑返回的时机

        function factorial(num) {
            if(num == 1){
                return 1;
            }
            return num * factorial(num - 1);

            // 简写
            // return (num == 1) ? 1 : num * factorial(--num);
        }
        
        console.log(factorial(5));// 阶乘运算
    </script>
</body>
</html>